package team.scau.laboratory_repair.common.activiti.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.task.Task;
import team.scau.laboratory_repair.common.utils.DateTool;

import java.util.Date;

/**
 * @author 30254
 * creadtedate:2018/10/22
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RepairTaskDto {
    private String id;
    private String taskName;
    private String assignee;
    private String startTime;
    private String endTime;
    private String procId;

    public RepairTaskDto(HistoricTaskInstance h, String name) {
        id = h.getId();
        taskName = h.getName();
        assignee = name;
        startTime = DateTool.formatDate(h.getStartTime());
        endTime = DateTool.formatDate(h.getEndTime());
        procId = h.getProcessInstanceId();
    }

    public RepairTaskDto(Task t, String name) {
        id = t.getId();
        taskName = t.getName();
        assignee = name;
        startTime = DateTool.formatDate(
                t.getCreateTime() != null ? t.getCreateTime()
                : (t.getClaimTime() != null ? t.getClaimTime()
                : t.getDueDate())
        );
        procId = t.getProcessInstanceId();
    }
}
